﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
///ValidataUI 的摘要说明
/// </summary>
public class ValidataUI
{
    public static IEnumerable<Control> GetValidata(ConfigColumns cCol)
    {
        if (cCol.EditShowRequired)
        {
            RequiredFieldValidator requiredV = new RequiredFieldValidator();
            requiredV.ErrorMessage = "*";
            requiredV.SetFocusOnError = true;
            requiredV.ValidationGroup = "Edit";
            requiredV.ControlToValidate = cCol.ColumnName + "_EditShow";
            requiredV.Display = ValidatorDisplay.Dynamic;
            yield return requiredV;
        }

        if (cCol.EditShowRange)
        {
            RangeValidator rangeV = new RangeValidator();
            rangeV.ID = cCol.ColumnName + "_range";
            rangeV.ValidationGroup = "Edit";
            rangeV.MinimumValue = cCol.EditShowRangeMinValue;
            rangeV.MaximumValue = cCol.EditShowRangeMaxValue;
            rangeV.ControlToValidate = cCol.ColumnName + "_EditShow";
            rangeV.ErrorMessage = rangeV.MinimumValue + " - " + rangeV.MaximumValue;
            rangeV.SetFocusOnError = true;
            rangeV.Type = cCol.EditShowRangeType;
            rangeV.Display = ValidatorDisplay.Dynamic;

            yield return rangeV;
        }
        if (cCol.EditShowRegExp)
        {
            RegularExpressionValidator regV = new RegularExpressionValidator();
            regV.ID = cCol.ColumnName + "_regexp";
            regV.ControlToValidate = cCol.ColumnName + "+EditShow";
            regV.SetFocusOnError = true;
            regV.Display = ValidatorDisplay.Dynamic;
            regV.ValidationGroup = "Edit";
            regV.ValidationExpression = cCol.EditShowRegExpText;
            regV.ErrorMessage = cCol.EditShowRegExpErrMessage;

            yield return regV;
        }
    }
}
